#if BaseOn
using System;
using System.Data.SqlServerCe;
#endif


namespace Belmost4PDA.DatabaseWorkPDA
{
    public class QueryExec
    {
        private int pErrorCode = -1;
        /// <summary>
        /// Gets the error code.
        /// </summary>
        /// <value>The error code.</value>
        public int ErrorCode
        {
            get { return pErrorCode; }
        }
        private string pErrorMsg = "No error";
        /// <summary>
        /// Gets the error Message.
        /// </summary>
        /// <value>The error Message.</value>
        public string ErrorMsg
        {
            get { return pErrorMsg; }
        }


        /// <summary>
        /// Executes SQL.
        /// </summary>
        /// <param name="SQL">The SQL-command to execute.</param>
        /// <returns></returns>
        public virtual bool Execute(string SQL)
        {
#if BaseOn
            try
            {
                //if (SQL.LastIndexOf("'", 0) != -1)
                //    SQL = SQL.Replace("'", "''");
                SqlCeCommand command = new SqlCeCommand(SQL, DataBase.Get(), DataBase.GetTrans());
                //throw new Exception(SQL);
                command.ExecuteNonQuery();
                DataBase.RestartTransaction();
            }
            catch(Exception ex)
            {
                pErrorMsg = ex.Message;
                pErrorCode = 1;
                throw;
                //return false;
            }
#endif
            return true;
        }
    }
}
